package com.zr.daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.zr.dao.LsjlDaoljc;
import com.zr.model.JL;
import com.zr.model.SQ;
import com.zr.util.JDBCUtil;

public class LsjlDaoImplljc implements LsjlDaoljc{
	//通过page和rows获取所有审批处理记录
	@Override
	public List<JL> findAllJL(int page, int rows) {
		List<JL> j = new ArrayList<>();
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT blog.cname,blog.id,blog.nr,blog.score,blog.sid,blog.sj,");
		sql.append(" blog.sqsj,blog.tname,blog.zt FROM blog");
		sql.append(" LIMIT ?,?");
		Connection con = JDBCUtil.getConnection();
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			pst.setInt(1, (page-1)*rows);
			pst.setInt(2, rows);
			ResultSet rs = pst.executeQuery();
			while(rs.next()){
				JL s = new JL();
				s.setCname(rs.getString("cname"));
				s.setNr(rs.getString("nr"));
				s.setSid(rs.getInt("sid"));
				s.setSj(rs.getString("sj"));
				s.setTname(rs.getString("tname"));
				s.setZt(rs.getString("zt"));
				s.setSqsj(rs.getString("sqsj"));
				s.setId(rs.getInt("id"));
				j.add(s);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return j;
	}
	//获取审批处理记录总数
	@Override
	public int countJL() {
		int count = 0;
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT COUNT(blog.id) as count ");
		sql.append(" FROM blog");
		Connection con = JDBCUtil.getConnection();
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			ResultSet rs = pst.executeQuery();
			while(rs.next()){
				count =Integer.parseInt(rs.getString("count"));
			}	
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return count;
	}

}
